|
|
 |
|
|
|
|
Vx = -Vx
End If
If (Cy < ymin) Then
Cy = 2 * ymin - Cy
Vy = -Vy
ElseIf (Cy > ymax) Then
Cy = 2 * ymax - Cy
Vy = -Vy
End If
End Sub
' Draw the circle on the indicated picture box. Public Sub Sprite_DrawSprite(ByVal pic As PictureBox)
pic.FillColor = Color
pic.Circle (Cx, Cy), Radius, Color
End Sub |
|
|
|
|
|
|
|
|
Because each sprite class implements the generic Sprite methods, the program can treat the different kinds of sprites uniformly. The program can create a sprite of any sprite class and assign it to a variable of type Sprite. The program can then invoke the object's MoveSprite and DrawSprite methods without worrying about which kind of object it really is. |
|
|
|
|
|
|
|
|
Example program Sprites, shown in Figure 9.2, uses this method to animate balls, triangles, and rectangles that bounce and spin. |
|
|
|
|
|
|
|
|
The following code shows how program Sprites animates its sprite objects. References to the sprites are stored in the Sprites array. For each frame, the program loops through the Sprites array telling each sprite to draw itself and then move itself to a new position for the next frame. |
|
|
|
|
|
|
|
|
Figure 9.2
Program Sprites draws balls, triangles, and
rectangles that bounce and spin. |
|
|
|
|
|